import com.sky.domain.Student;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.*;

public class demotest {

    public static void main(String[] args) throws InterruptedException {
        List<Integer> list = new ArrayList<>();
        Random random = new Random();

        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(4  , 8, 5, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100000), new ThreadPoolExecutor.AbortPolicy());

        CountDownLatch latch = new CountDownLatch(1000);
        //线程异执行
        for(int i = 0; i<1000;i++){
            CompletableFuture.supplyAsync(()->test1_1(list),
                    poolExecutor
            ).thenAccept(dto -> {//获取返回结果
                System.out.println(dto);
                latch.countDown();
            });
        }
        latch.await();
        System.out.println("---------------------------------------------------------------------------");
        System.out.println(list.stream().distinct().count());

    }

    public static int number = 0;
    public static synchronized String test1_1(List<Integer> list){
        list.add(number++);
        return Thread.currentThread().getName() + ":" + System.currentTimeMillis() + "-" + number;
    }


    public static void add(StringBuilder stringBuilder){
        stringBuilder.append("success");
    }

    public static void add1( Student student){
        student.setName("false");
    }

}
